package com.ms.p2p.entity;


import com.ms.common.utils.PageData;
import com.ms.common.utils.Tools;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 分页类
 * @author FH QQ 313596790[青苔]
 * 创建时间：2014年6月28日
 */
public class Page  implements Serializable {

	private List<?> list = new ArrayList();// 数据List

	public List<?> getList() {
		return list;
	}

	public void setList(List<?> list) {
		this.list = list;
	}

	public Page(List<?> list) {
		super();
		this.list = list;
	}

//currentPage":1,"pageSize":20,"begin":0,"totalCount":78,"totalPage":4,
//	private int showCount; //每页显示记录数
	public int pageSize;		//总页数
	public int totalCount;	//总记录数
	public int currentPage;	//当前页
	public int begin;	//当前记录起始索引
	public boolean entityOrField;	//true:需要分页的地方，传入的参数就是Page实体；false:需要分页的地方，传入的参数所代表的实体拥有Page属性
	public String pageStr;		//最终页面显示的底部翻页导航，详细见：getPageStr();
	public PageData pd = new PageData();
	public int totalPage;
	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public String getPageStr() {
		return pageStr;
	}
	public void inVilidate(){



	}
	public Page(){
			if(StringUtils.isNotBlank(pd.getString("rp"))){
				this.pageSize = Integer.parseInt(pd.getString("rp"));
			}else{
				this.pageSize = 20;
			}
	}
	
	public int getTotalPage() {
		if(totalCount%pageSize==0)
			totalPage = totalCount/pageSize;
		else
			totalPage = totalCount/pageSize+1;
		return totalPage;
	}
	

	public int getCurrentPage() {
		if(currentPage<=0)
			currentPage = 1;
		if(currentPage>getTotalPage())
			currentPage = getTotalPage();
		return currentPage;
	}
	
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	

	
	public void setPageStr(String pageStr) {
		this.pageStr = pageStr;
	}
	

	
	public int getCurrentResult() {
		begin = (getCurrentPage()-1)*getPageSize();
		if(begin<0)
			begin = 0;
		return begin;
	}

	public int getBegin() {
		return begin;
	}

	public void setBegin(int begin) {
		this.begin = begin;
	}

	public boolean isEntityOrField() {
		return entityOrField;
	}
	
	public void setEntityOrField(boolean entityOrField) {
		this.entityOrField = entityOrField;
	}
	
	public PageData getPd() {
		return pd;
	}

	public void setPd(PageData pd) {
		this.pd = pd;
	}
	
}
